<?php
$show_validator = true;
include TMPL_PATH.'public/header.phtml';
?>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/jscal2.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/border-radius.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/win2k.css"/>
<script type="text/javascript" src="/statics/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/statics/js/calendar/lang/zh-cn.js"></script>
<script type="text/javascript">
<!--
	$(function(){
	$.formValidator.initConfig({formid:"theForm",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
	$("#type_name").formValidator({onshow:"请输入优惠码",onfocus:"请输入优惠码"}).inputValidator({min:1,onerror:"请输入优惠码"});
 	$("#type_money").formValidator({onshow:"请输入优惠金额",onfocus:"请输入优惠金额"}).inputValidator({min:1,onerror:"请输入优惠金额"}).regexValidator({regexp:"[1-9]\\d*(.\\d{2})?$",onerror:"金额必须为整数或者小数"});

	})
//-->
</script>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
        <a href='<?php echo U('coupon/coupon_list');?>'><em>优惠码列表</em></a><span>|</span>
        <a href='javascript:;' class="on" ><em><?php if($bonus):?>编辑<?php else:?>添加<?php endif;?>优惠码</em></a><span>|</span>
        <a href='<?php echo U('Coupon/coupon_edit_special');?>' ><em>批量添加优惠码</em></a>
    </div>
</div>
<div class="pad_10">
<div class="common-form">
<form name="theForm" action="__SELF__" method="post" id="theForm">
<div id="price-div">
<table width="100%" class="table_form contentWrap">
    <tbody>
     <tr>
	    <th width="120">优惠码编号</th>
	    <td><input type="text" class="input-text" name="coupon_code" value="<?php echo isset($bonus['coupon_code']) ? $bonus['coupon_code'] : null;?>" id="coupon_code"/></td>
	  </tr>
	  <tr>
          <th>类型1： 金额优惠 <input type="radio" name="coupon_type" value="1"  <?php if(isset($bonus['coupon_money']) && ($bonus['status'] != 4)) echo 'checked="checked"';?>/></th>
	    <td><input type="text" class="input-text" name="coupon_money" value="<?php echo isset($bonus['coupon_money']) && ($bonus['status'] != 4) ? $bonus['coupon_money'] : null;?>" id="coupon_money"/><div class="infoShow">美元 （优惠金额）</div></td>
      </tr>
    <tr>
	    <th>类型2： 折扣优惠 <input type="radio" name="coupon_type" value="2"  <?php if(isset($bonus['coupon_money']) && ($bonus['status'] == 4)) echo 'checked="checked"';?>/></th>
	    <td><input type="text" class="input-text" name="coupon_money2" value="<?php echo isset($bonus['coupon_money']) && ($bonus['status'] == 4) ? $bonus['coupon_money'] : null;?>" id="coupon_money"/><div class="infoShow">% (折扣率 1 - 100 如9折请填写90)</div></td>
      </tr>
	  <!--<tr>
	    <th>如何发放此类型优惠码</th>
	    <td>
      <input name="send_type" value="0" <?php if(!isset($bonus['send_type']) || (isset($bonus['send_type']) && $bonus['send_type']==0)) echo 'checked="true"';?> onclick="showunit(0)" type="radio">按用户发放        
       <input name="send_type" value="1" <?php if(isset($bonus['send_type']) && $bonus['send_type']==1) echo 'checked="true"';?> onclick="showunit(1)" type="radio">按订单金额发放      
	  <input name="send_type" value="2" <?php if(isset($bonus['send_type']) && $bonus['send_type']==2) echo 'checked="true"';?> onclick="showunit(2)" type="radio">按会员生日发放     
     </td>
	  </tr>-->
	  <tr id="send_type_1">
	  	  <tr id="send_type_1">
	    <th>订单上限</th>
	    <td><input type="text" class="input-text" name="max_amount" value="<?php echo isset($bonus['max_amount']) ? $bonus['max_amount'] : null;?>"/><div class="infoShow">使用优惠码最大金额</div></td>
	  </tr>
	    <th>订单下限</th>
	    <td><input type="text" class="input-text" name="min_amount" value="<?php echo isset($bonus['min_amount']) ? $bonus['min_amount'] : null;?>"/><div class="infoShow">使用优惠码最小金额</div></td>
	  </tr>
	  <tr>
              <th>过期时间</th>
	    <td><input class="input-text" name="expiration_time" type="text" id="expiration_time" size="20" value="<?php echo isset($bonus['expiration_time'])&&!empty($bonus['expiration_time']) ? date("Y-m-d",$bonus['expiration_time']) : null;?>"/>
	    <div class="infoShow">可选，不填写过期时间，默认为系统最大过期时间2038-01-19</div>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "expiration_time",
		    trigger    : "expiration_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
            </script>
            </td>
            
	  </tr>
          
    <tr>
	    <th width="120">备注</th>
        <td><textarea name='favorable_group_desc' ><?php echo isset($bonus['favorable_group_desc']) ? $bonus['favorable_group_desc'] : '';?></textarea><br/>
        </td>    
    </tr>    
	 <!--<tr class="xianshi02">
	    <th width="120">发放起始日期</th>
	    <td><input class="input-text"  name="send_start_date" type="text" id="send_start_date" size="22" value='<?php echo date('Y-m-d', isset($bonus['send_start_date']) ? $bonus['send_start_date'] : time());?>'"/>
	    <div class="infoShow">只有当前时间介于起始日期和截止日期之间时，此类型的红包才可以发放</div>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "send_start_date",
		    trigger    : "send_start_date",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>
	  <tr class="xianshi02">
	    <th width="120">发放结束日期</th>
	    <td><input class="input-text"  name="send_end_date" type="text" id="send_end_date" size="22" value='<?php echo date('Y-m-d', isset($bonus['send_end_date']) ? $bonus['send_end_date'] : strtotime('+1 months'));?>'/>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "send_end_date",
		    trigger    : "send_end_date",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>
	  <tr>
	  	<th width="120">是否启用使用限制</th>
		<td>
			<input type="radio" name="restrict" value="0" onclick="xianshi(0);" <?php if(isset($bonus['restrict']) || $bonus['restrict']==0) echo 'checked';?>> 是&nbsp;&nbsp;&nbsp;&nbsp;
	  		<input type="radio" name="restrict" value="1" onclick="xianshi(1);" <?php if($bonus['restrict']>0) echo 'checked';?> > 否
		</td>
	  </tr>
	  <tr class="xianshi">
	    <th width="120">使用起始日期</th>
	    <td><input class="input-text" name="use_start_date" type="text" id="use_start_date" size="22" value='<?php echo date('Y-m-d', isset($bonus['use_start_date']) ? $bonus['use_start_date'] : time());?>' />
	    <div class="infoShow">只有当前时间介于起始日期和截止日期之间时，此类型的红包才可以使用</div>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "use_start_date",
		    trigger    : "use_start_date",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>
	  <tr class="xianshi">
	    <th width="120">使用结束日期</th>
	    <td><input class="input-text" name="use_end_date" type="text" id="use_end_date" size="22" value='<?php echo date('Y-m-d', isset($bonus['use_end_date']) ? $bonus['use_end_date'] :  strtotime('+1 months'));?>'/>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "use_end_date",
		    trigger    : "use_end_date",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>-->
  </tbody>
</table>
</div>
    <div class="bk15"></div>
    <input name="dosubmit" type="submit" value="提交" class="button" id="dosubmit" />
</form>
</div>
</div>
</body>
</html>
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

$(function()
{
  get_value = '<?php echo isset($bonus['send_type']) ? $bonus['send_type'] : null?>';
  restrict = '<?php echo isset($bonus['restrict']) ? $bonus['restrict'] : null?>';
  showunit(get_value);
  xianshi(restrict);
});
function showunit(get_value)
{
	$("#send_type_1").css('display',(get_value == 1) ? "" : "none");
	if(get_value == 0 || get_value == 2){
		$(".xianshi02").css('display',"none");
	}else{
		$(".xianshi02").css('display',"");
	}
  return;
}

function xianshi(restrict)
{
	$(".xianshi").css('display',(restrict == 0) ? "" : "none");
  return;
}
//-->
</script>
